package com.yueya.business.senior.model;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import net.sf.json.JSONObject;

/**
 * 老人体检信息
 * 
 * @author 梁涛
 *
 */
public class SeniorExamination extends Model<SeniorExamination> {

	private static final long serialVersionUID = 1L;
	public static SeniorExamination dao = new SeniorExamination();

	public boolean save(SeniorExamination dao) {
		return dao.save();
	}

	public boolean update(SeniorExamination dao) {
		return dao.update();
	}

	public SeniorExamination getDetailById(String id) {

		String sql = "select * from jg_senior_examination sb ";
		sql += " where sb.del_flag='0' and  sb.examination_id =?  ";

		SeniorExamination r = dao.findFirst(sql, id);

		return r;
	}

	public Page<SeniorExamination> paginate(int pageNumber, int pageSize, JSONObject jo) {
		String select = "select se.examination_id examinationid,se.examination_date examinationdate,se.hospital_id hospitalid,sb.senior_id seniorid,sb.senior_name seniorname,sb.id_card idcard,sb.bedname";
		StringBuffer sql = new StringBuffer(
				" from jg_senior_examination se , v_senior_base sb where sb.del_flag='0' and se.senior_id = sb.senior_id ");

		// 名字或身份证
		if (jo.containsKey("name")) {
			String name = jo.getString("name");
			if (StrKit.notBlank(name)) {
				sql.append(" and (sb.senior_name like '%" + name + "%' or sb.id_card like  '%" + name + "%'  )");
			}
		}
		sql.append(" order by se.registrant_date desc");
		System.out.println(select + sql.toString());
		return dao.paginate(pageNumber, pageSize, select, sql.toString());
	}
}
